import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Switch, Redirect } from 'react-router'
import { PrivateRoute } from 'components/route'
import { PaddingContainer } from 'components/containers'
import ClassList from './list'
import NewTask from './new'

export default class ProjectClassConfig extends Component {
  static propTypes = {
    setParentActiveItem: PropTypes.func.isRequired,
  }

  componentDidMount = () => {
    const { setParentActiveItem } = this.props
    setParentActiveItem('download')
  }

  render() {
    const { match, location, project } = this.props
    return (
      <PaddingContainer>
        <Switch location={location}>
          <PrivateRoute
            path={`${match.url}/`}
            render={props => <ClassList {...props} project={project} />}
            exact
          />
          <PrivateRoute
            path={`${match.url}/new`}
            render={props => <NewTask {...props} project={project} />}
            exact
          />
          <Redirect from={`${match.url}`} to={`${match.url}`} />
        </Switch>
      </PaddingContainer>
    )
  }
}
